package com.pattern.observer.case02;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class MessageEventHandler {

    @EventListener(Purchase02Event.class)
    @Async
    public void updateStock() throws InterruptedException {
        Thread.sleep(2000);
        log.info("库存扣减");
    }

    @EventListener(Purchase02Event.class)
    @Async
    public void insertLog() throws InterruptedException {
        Thread.sleep(1000);
        log.info("-----日志记录-----");
    }

}
